// Application specific javascript

$(function () {
    /*	$("#twitter_quote .quote").getTwitter({
    userName: "astrorecruit",
    numTweets: 2,
    loaderText: "Loading tweets...",
    slideIn: true,
    showHeading: false,
    headingText: "Latest Tweets",
    showProfileLink: false
    }); */



    //Scrolling client logos
    $('#client_logos').contentSlider();

    //Choose country drop down
    $('.choose_country').click(function () {
        $('.country_list').toggle();
        $(this).toggleClass('current');
        return false;
    });

    //Sector dropdown
    $('a.choose_sector').click(function () {
        $('.sectors_list').toggle();
        $(this).toggleClass('current');
        return false;
    });

    //Hover location map
    $("#location_map li").hover(function () {
        var activeLocation = $(this).find("a").attr("href");
        $(activeLocation).fadeIn();
    }, function () {
        var activeLocation = $(this).find("a").attr("href");
        $(activeLocation).fadeOut();
    }
	);
    $("#location_map li a").click(function () {
        return false;
    });

    //Offices page
    //	$('.office_locations').hide();
    //	$('#united_kingdom').show();
    //	$('#office_select').change(function(){
    //		var office_location = $(this).val();
    //		$('.office_locations').hide();
    //		$('#'+office_location).fadeIn();
    //	});
    //	$('#office_select').change();

    // Featured jobs homepage ajax pagination
});


$.fn.placeholderInput = function(){
	return this.each(function(){
		$(this).find('input.text').each(function(){
			var input = $(this);
			var label = input.prev('label').text();
			
			input.val(label).addClass('placeholder').focus(function(){
				if (input.val() == label) input.removeClass('placeholder').val('');
			}).blur(function(){
				if (input.val() == '') input.val(label).addClass('placeholder')
			});
		});
	});
}

$.fn.contentSlider = function(){
	return this.each(function(){
		var SCROLL_SPEED = 500;
		var container = $(this);
		var slides = $('>div', container);
		var ul = $('>ul',slides);
		var scrollAmount = 850;
		
		var items = $('>li',ul);
		var itemsWidth = items.outerWidth(true) * items.length;
		
		items.clone().appendTo(ul);
		
		var slide = function(e){
			if(!slides.is(':animated')) {
				var currentScroll = slides.scrollLeft();

				if (e.data.direction == 'next') {
					slides.animate({scrollLeft: currentScroll+scrollAmount},{duration: SCROLL_SPEED, complete:function(){
						if (slides.scrollLeft()>=itemsWidth) slides.scrollLeft(slides.scrollLeft()-itemsWidth);
					}});
				} else {
					slides.animate({scrollLeft: currentScroll-scrollAmount},{duration: SCROLL_SPEED, complete:function(){
						if (slides.scrollLeft()<=0) slides.scrollLeft(itemsWidth);
					}});
				}
			}
		}
		
		// initialise slideshow
		slides.css({
			height: items.outerHeight()
		});
		ul.css({width: itemsWidth * 2 +'px'});
		
		$('<button class="slider_prev">Previous</button>').bind('click',{direction:'prev'},slide).appendTo(container);
		$('<button class="slider_next">Next</button>').bind('click',{direction:'next'},slide).appendTo(container);

	});
}

